r,y,g=map(int,input().split())
n=int(input())

result=0

for i in range(0,n):
    light,time=map(int,input().split())
    if light==0:
        result+=time
    elif light==1:
        result+=time
    elif light==2:
        result+=(time+r)
    else:
        pass

print(result)
